package com.qiyeji.real_estate.ProjectTask;

import com.qiyeji.real_estate.service.WorkService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.delegate.DelegateTask;
import org.camunda.bpm.engine.delegate.TaskListener;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class DeleteTemporaryWorkAsRefluse implements TaskListener {
    @Autowired
    WorkService workService;

    @Autowired
    RuntimeService runtimeService;

    /**用来指定任务的办理人*/
    @Override
    public void notify(DelegateTask delegateTask) {
        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(delegateTask.getProcessInstanceId()).singleResult();
        String pCode = processInstance.getBusinessKey();

        System.out.println("清空TemporaryWork数据！");
        workService.deleteByPCode(pCode);
    }
}
